package three;

import java.util.Scanner;

public class test11078 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n + 1];
        int[][] m = new int[n + 1][n + 1];
        int[] b = new int[n + 1];
        int max = 0;
        int min = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = scanner.nextInt();
        }
        MintrixChain(a, n, m);
        min = m[1][n];
        System.out.print(min + " ");
        MatrixChain(a, n, m);
        max = m[1][n];
        System.out.println(max);
        for (int i = 1; i <= n ; i++) {
            for (int j = 1; j <= n; j++) {
                int k = (i + j -1) % n;
                if(k==0)
                    k=n;
                b[j] = a[k];
            }
            MintrixChain(b, n, m);
            if (min > m[1][n]) {
                min = m[1][n];
            }
        }
        System.out.print(min + " ");
        for (int i = 1; i <= n ; i++) {
            for (int j = 1; j <= n; j++) {
                int k = (i + j - 1) % n;
                if(k==0)
                    k=n;
                b[j] = a[k];
            }
            MatrixChain(b, n, m);
            if (max < m[1][n]) {
                max = m[1][n];
            }
        }
        System.out.print(max);
    }

    private static void MintrixChain(int[] a, int n, int[][] m) {
        for (int i = 1; i <= n; i++) {
            m[i][i] = 0;
        }
        for (int r = 2; r <= n; r++) {
            for (int i = 1; i <= n - r + 1; i++) {
                int sum = 0;
                int j = r + i - 1;
                for (int l = i; l <= j; l++) {
                    sum = sum + a[l];
                }
                m[i][j] = sum + m[i + 1][j];
                for (int k = i + 1; k < j; k++) {
                    int t = m[i][k] + m[k + 1][j] + sum;
                    if (t < m[i][j]) {
                        m[i][j] = t;
                    }
                }
            }
        }
    }

    private static void MatrixChain(int[] a, int n, int[][] m) {
        for (int i = 1; i <= n; i++) {
            m[i][i] = 0;
        }
        for (int r = 2; r <= n; r++) {
            for (int i = 1; i <= n - r + 1; i++) {
                int sum = 0;
                int j = r + i - 1;
                for (int l = i; l <= j; l++) {
                    sum = sum + a[l];
                }
                m[i][j] = sum + m[i + 1][j];
                for (int k = i + 1; k < j; k++) {
                    int t = m[i][k] + m[k + 1][j] + sum;
                    if (t > m[i][j]) {
                        m[i][j] = t;
                    }
                }
            }
        }
    }

}
